package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/findAll_back")
public class FindAllStudentsServletback extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //把文件中的学生信息展示在 网页上把

        //中文乱码问题
        resp.setHeader("Content-Type","text/html;charset=utf-8");

        //文件流 读文件
        BufferedReader reader = new BufferedReader(new FileReader("g://stu.txt"));
        //  //输出流写到 浏览器上
        PrintWriter writer = resp.getWriter();
        String s;
        while ((s=reader.readLine())!=null){
            writer.write(s);
            writer.write("<br>");
        }
        reader.close();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
